package implementation {
import flash.display.DisplayObject;
import flash.display.Sprite;

import palf.Gallery;
import palf.visualEffects.VisualEffect;

internal class GalleryImplementation implements Gallery {

	private var target : Sprite;
	private var index_offset : int;
	private var effect : VisualEffect;

	public function GalleryImplementation(target : Sprite) {
		this.target = target;
	}

	public function applyEffect(effect : VisualEffect) : void {
		this.effect = effect;
		sort();
	}

	public function sort() : void {
		if (effect) {
			effect.apply(target, index_offset);
		}
	}

	public function selectIndex(index : uint) : void {
		index_offset = index % target.numChildren;
		sort();
	}

	public function selectItem(item : DisplayObject) : void {
		var index : int = target.getChildIndex(item);
		if (index > -1) {
			selectIndex(index);
		}
	}

	public function get index() : int {
		return index_offset;
	}

}

}
